from urllib.request import Request
from urllib.request import urlopen
from bs4 import BeautifulSoup
from urllib.request import ProxyHandler
from catch.read_file import read
from urllib.request import build_opener
from urllib.request import HTTPHandler
from urllib.request import install_opener

def get_home():
    url = 'https://m.weibo.cn/'
    cookie = open('../file/cookies.txt')
    head = {'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
            # 'Accept-Encoding': 'gzip, deflate, sdch, br',
            'Accept-Language': 'zh-CN,zh;q=0.8',
            'Cache-Control': 'max-age=0',
            'Connection': 'keep-alive', 'Host': 'm.weibo.cn',
            'Upgrade-Insecure-Requests': 1,
            'User-Agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Mobile Safari/537.36',
            'Cookie':cookie.readline()}


    print(head)

    proxy=ProxyHandler({'http':read()})
    request=Request(url=url,headers=head)
    opener=build_opener(proxy,HTTPHandler)
    install_opener(opener)

    respon=urlopen(request).read().decode('utf-8')
    soup=BeautifulSoup(respon,'lxml')
    print(soup.prettify())
if __name__=='__main__':
    get_home()
